package com.woniu.microassetserver.mapper;

import com.woniu.microcommonsserver.entity.AssetsParameterEntity;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface AssetsParameterMapper {

    /**
     * 根据参数进行分页查询
     * @param assetsParameterEntity
     * @return
     * @author luoyue
     */
    List<AssetsParameterEntity> findAllByParams(@Param("ap") AssetsParameterEntity assetsParameterEntity);


    /**
     *
     * @param id
     * @return
     */
    AssetsParameterEntity findRPIById(@Param("id") Long id);




    /**
     * 新增资产台账信息
     *
     * @param assetsParameterEntity
     * @return 受影响的行数
     * @author luoyue
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "ap.id"
    )
    @Insert("insert into assets_parameter " +
            "(asset_name,asset_number,fk_device_system_id,fk_device_type_id,model,brands,commissioning_date,date_of_production,designed_life,asset_images,asset_information,fk_vendor_id,status)" +
            " values(#{ap.assetName},#{ap.assetNumber},#{ap.fkDeviceSystemId},#{ap.fkDeviceTypeId},#{ap.model},#{ap.brands},#{ap.commissioningDate},#{ap.dateOfProduction},#{ap.designedLife},#{ap.assetImages},#{ap.assetInformation},#{ap.fkVendorId},#{ap.status})")
    int saveAssetsParameter(@Param("ap") AssetsParameterEntity assetsParameterEntity);



    /**
     * 根据ID查询车辆
     *
     * @param id
     * @return
     * @author luoyue
     */
    @Results({
            @Result(id = true, property = "id", column = "id", javaType = Long.class),
            @Result(property = "assetName", column = "asset_name", javaType = String.class),
            @Result(property = "assetNumber", column = "asset_number", javaType = String.class),
            @Result(property = "fkDeviceSystemId", column = "fk_device_system_id", javaType = Long.class),

            @Result(property = "fkDeviceTypeId", column = "fk_device_type_id", javaType = Long.class),
            @Result(property = "model", column = "model", javaType = String.class),
            @Result(property = "brands", column = "brands", javaType = String.class),

            @Result(property = "commissioningDate", column = "commissioning_date", javaType = Date.class),
            @Result(property = "dateOfProduction", column = "date_of_production", javaType = Date.class),
            @Result(property = "designedLife", column = "designed_life", javaType = Long.class),

            @Result(property = "assetImages", column = "asset_images", javaType = String.class),
            @Result(property = "assetInformation", column = "asset_information", javaType = String.class),
            @Result(property = "fkVendorId", column = "fk_vendor_id", javaType = Long.class),

            @Result(property = "status", column = "status", javaType = Long.class),


            /*@Result(property = "customerInfo", column = "fk_customer_id", javaType = AssetsParameterBean.class, one =
            @One(select = "com.woniuxy.creditsystem.common.mapper.CustomerMapper.getOneById", fetchType = FetchType.LAZY)),*/
    })
    @Select("select * from assets_parameter where id = #{id}")
    AssetsParameterEntity getOneById(Long id);





    /**
     * 修改资产信息
     *v.
     * @param assetsParameterEntity
     * @return 受影响的行数
     */
    @Update("<script>" +
            "update assets_parameter" +
            "<set>" +
            "<if test='ap.assetName != null'>" +
            "asset_Name = #{ap.assetName}," +
            "</if>" +
            "<if test='ap.assetNumber != null'>" +
            "asset_number = #{ap.assetNumber}," +
            "</if>" +
            "<if test='ap.fkDeviceSystemId != null'>" +
            "fk_device_system_id = #{ap.fkDeviceSystemId}," +
            "</if>" +
            "<if test='ap.fkDeviceTypeId != null'>" +
            "fk_device_type_id = #{ap.fkDeviceTypeId}," +
            "</if>" +
            "<if test='ap.model != null'>" +
            "model = #{ap.model}," +
            "</if>" +
            "<if test='ap.brands != null'>" +
            "brands = #{ap.brands}," +
            "</if>" +
            "<if test='ap.assetImages != null'>" +
            "asset_images = #{ap.assetImages}," +
            "</if>" +
            "<if test='ap.assetInformation != null'>" +
            "asset_information = #{ap.assetInformation}," +
            "</if>" +

            "</set>" +
            "where id = #{ap.id}" +
            "</script>")
    int updateAssetsParameter(@Param("ap") AssetsParameterEntity assetsParameterEntity);


    /**
     * 删除车辆信息
     * @param id
     * @return 受影响的行数
     */

    @Delete("delete from assets_parameter where id = #{id}")
    int deleteAssetsParameter(@Param("id")Integer id);

}
